#include <bits/stdc++.h>

using namespace std;

struct B{
    int s,p;
    const bool operator < (const B &b) const{return p<b.p;}
};
const int maxn=100005;
B bales[maxn];
bool ok[maxn];

int main(){
    int last,n;

    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&bales[i].s,&bales[i].p);
    sort(bales+1,bales+1+n);
    last=bales[1].p;
    ok[0]=ok[n]=1;
    for(int i=1;i<n;i++){
        last=max(last,bales[i].p+bales[i].s);
        if(bales[i+1].p>last) ok[i]=1;
    }
    last=bales[n].p;
    for(int i=n-1;i>=1;i--){
        last=min(last,bales[i+1].p-bales[i+1].s);
        if(bales[i].p<last) ok[i]=1;
    }

    int ans=0;
    for(int i=1;i<n;i++) if(!ok[i]) ans+=bales[i+1].p-bales[i].p;
    printf("%d\n",ans);
}

